package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Scanner;

/**
 * 调用Person类中所有的公开且无参，名字中含有字母s的方法
 */
public class Test5 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入类名:");
        Class cls = Class.forName(sc.nextLine());
        Object o = cls.newInstance();
        Method[] methods = cls.getMethods();
        for(Method m : methods){
            String mName = m.getName();
            if(m.getModifiers()== Modifier.PUBLIC && m.getParameterCount() == 0 && mName.contains("s")){
                //Method method = cls.getMethod(mName);
                m.invoke(o);
            }
        }

    }
}
